package overrideoverwrite;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Person
 * @Date 2024/11/27 16:57 15
 * @Author Jack Chen
 * @Description serenity-cucumber-auto-project-jack
 * @Version 1.0
 */

public class Person implements Cloneable {
    private String name;
    private int age;
    List<String> hobbies;
    public Person(String name, int age , List<String> hobbies) {
        this.name = name;
        this.age = age;
        this.hobbies = hobbies;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public List<String> getHobbies() {
        return hobbies;
    }

    public void setHobbies(List<String> hobbies) {
        this.hobbies = hobbies;
    }

    @Override
    public Person clone() throws CloneNotSupportedException {
        //  浅拷贝
        Person person = (Person) super.clone();

        //  深拷贝
        person.setHobbies(new ArrayList<>(hobbies));

        return person;
    }

    public String toString() {
        return "Person [name=" + name + ", age=" + age + ", hobbies=" + hobbies + "]";
    }
}
